
#include <cstdlib>
#include <stdio.h>

#include "threading/Mutex.h"

Mutex::Mutex()
{
    if(pthread_mutex_init(&mutex_, NULL) < 0)
    {
        perror("pthread_mutex_init() : ");
        exit(EXIT_FAILURE);
    }
}

Mutex::~Mutex()
{
    if(pthread_mutex_destroy(&mutex_) < 0)
    {
        perror("pthread_mutex_destroy() : ");
        exit(EXIT_FAILURE);
    }
}

void Mutex::lock()
{
    if(pthread_mutex_lock(&mutex_) < 0)
    {
        perror("pthread_mutex_lock() : ");
        exit(EXIT_FAILURE);
    }
}

void Mutex::unlock()
{
    if(pthread_mutex_unlock(&mutex_) < 0)
    {
        perror("pthread_mutex_unlock() : ");
        exit(EXIT_FAILURE);
    }
}
